Skip to content

feat(net/socket): implement net reuse port - #2173

Draft
mistcoversmyeyes wants to merge 3 commits into
DragonOS-Community:masterfrom
mistcoversmyeyes:feat/net-reuseport-1848
Draft

feat(net/socket): implement net reuse port #2173
mistcoversmyeyes wants to merge 3 commits into
DragonOS-Community:masterfrom
mistcoversmyeyes:feat/net-reuseport-1848

Conversation

@mistcoversmyeyes

Copy link
Copy Markdown
Contributor

Replace the single-owner tcp_port_table (HashMap<u16, RawPid>) with
multi-binding records mirroring the UDP side. A new binding is accepted
when every conflicting binding shares SO_REUSEPORT or SO_REUSEADDR with
the requester. Each record is identified by (iface_nic_id, smoltcp
handle), so unbinding is exact without threading an extra id through the
socket state. The generic bind_port/unbind_port/bind_ephemeral_port
helpers are superseded by per-protocol variants.
Store the flag in TcpSocketOptions and wire it into setsockopt/getsockopt,
mirroring the existing SO_REUSEADDR handling. The value is snapshotted at
bind() time, matching Linux semantics where SO_REUSEPORT must be set
before bind() to participate in port sharing.
Pass SO_REUSEPORT/SO_REUSEADDR from TcpSocket options into Init::bind and
Init::listen, routing port registration through bind_tcp_port and
bind_tcp_ephemeral_port. Every listening smoltcp socket that belongs to a
reuseport listener - the primary socket, per-interface and backlog
sockets, and the replacement socket created on accept - is marked with
set_reuseport so the smoltcp dispatcher can distribute SYNs across the
group. All unbind call sites now release by (iface_nic_id, handle).
@github-actions github-actions Bot added the enhancement New feature or request label Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant